package com.unisedu.hr.service;

import com.unisedu.hr.basic.IBaseEntity;
import com.unisedu.hr.basic.IBaseService;
import com.unisedu.hr.dao.OfficeDao;
import com.unisedu.hr.entity.Office;
import com.unisedu.hr.layui.Table;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OfficeService implements IBaseService {

    private OfficeDao officeDao;

    @Autowired
    public OfficeService(OfficeDao dao){
        this.officeDao = dao;
    }


    @Override
    public IBaseEntity get(Integer id) {
        return null;
    }

    @Override
    public List<IBaseEntity> findList(IBaseEntity entity) {
        return officeDao.findList(entity);
    }

    @Override
    public Table findPage(IBaseEntity entity, Integer page, Integer limit) {
        return null;
    }

    @Override
    public IBaseEntity insert(IBaseEntity entity) {
        return null;
    }

    @Override
    public IBaseEntity update(IBaseEntity entity) {
        return null;
    }

    @Override
    public Integer delete(Integer id) {
        return null;
    }

    public List<IBaseEntity> findTreeData(){
        Office office = new Office();
        office.setLevel(0);
        List list = findList(office);
        for (int i = 0; i < list.size(); i++) {
            Office o = (Office) list.get(i);
            Office child = new Office();
            child.setParentId(o.getId());
            List children = findList(child);
            o.setChildren(children);
        }
        return list;
    }

}
